package com.roc.web.action.merinfo;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

public class MerDtInfoForysbSearchCondition extends BaseSearchCondition {

	private String mobile;
	private String merName;
	private String pid;
	private String oprNo;
	private String status;
	private String minDate;
	private String maxDate;
	private String idCardStatus;
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		if(Constance.isNotEmpty(mobile)){ 
			filedBeanList.add(new WhereHQLFieldBean("a.account_no", mobile.trim(), "=", false));
		}
		if(Constance.isNotEmpty(merName)){ 
			filedBeanList.add(new WhereHQLFieldBean("a.name", merName.trim(), "=", false));
		}
		if(Constance.isNotEmpty(pid)){ 
			filedBeanList.add(new WhereHQLFieldBean("a.pid", pid.trim(), "=", false));
		}
		if(Constance.isNotEmpty(oprNo)){ 
			filedBeanList.add(new WhereHQLFieldBean("a.updated_by", oprNo.trim(), "=", false));
		}
		if(!"99".equals(status) && Constance.isNotEmpty(status)){
			if("5".equals(status)){
				filedBeanList.add(new WhereHQLFieldBean("a.status", "1", "=", false));
				filedBeanList.add(new WhereHQLFieldBean("a.ext5", "1", "=", false));
			}else{
				filedBeanList.add(new WhereHQLFieldBean("a.status", status.trim(), "=", false));
			}
		}
		if(Constance.isNotEmpty(minDate)){
			if("99".equals(status) || "0".equals(status)){ //状态为空或未领取-提交时间
				filedBeanList.add(new WhereHQLFieldBean("to_char(a.created_at,'yyyyMMdd')", minDate.trim(), ">=", false));
			}
			if("1".equals(status) || "5".equals(status)){ //状态为审核通过/解限-更新时间
				filedBeanList.add(new WhereHQLFieldBean("to_char(a.updated_at,'yyyyMMdd')", minDate.trim(), ">=", false));
			}
			if("2".equals(status) || "4".equals(status)){ //状态为驳回/限制-更新时间
				filedBeanList.add(new WhereHQLFieldBean("to_char(a.updated_at,'yyyyMMdd')", minDate.trim(), ">=", false));
			}
			if("3".equals(status)){ //状态为待审核-取件时间
				filedBeanList.add(new WhereHQLFieldBean("to_char(b.create_at,'yyyyMMdd')", minDate.trim(), ">=", false));
			}
		}
		if(Constance.isNotEmpty(maxDate)){
			if("99".equals(status) || "0".equals(status)){ //状态为空或未领取-提交时间
				filedBeanList.add(new WhereHQLFieldBean("to_char(a.created_at,'yyyyMMdd')", maxDate.trim(), "<=", false));
			}
			if("1".equals(status) || "5".equals(status)){ //状态为审核通过/解限-更新时间
				filedBeanList.add(new WhereHQLFieldBean("to_char(a.updated_at,'yyyyMMdd')", maxDate.trim(), "<=", false));
			}
			if("2".equals(status) || "4".equals(status)){ //状态为驳回/限制-更新时间
				filedBeanList.add(new WhereHQLFieldBean("to_char(a.updated_at,'yyyyMMdd')", maxDate.trim(), "<=", false));
			}
			if("3".equals(status)){ //状态为待审核-取件时间
				filedBeanList.add(new WhereHQLFieldBean("to_char(b.create_at,'yyyyMMdd')", maxDate.trim(), "<=", false));
			}
		}
		if(StringUtils.isNotEmpty(idCardStatus)){
			if("0".equals(idCardStatus)){
				filedBeanList.add(new WhereHQLFieldBean("a.ext1 is null"));
			}else if("1".equals(idCardStatus)){
				filedBeanList.add(new WhereHQLFieldBean("a.ext1 is not null"));
			}
		}
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		StringBuffer sb = new StringBuffer();
		sb.append("select count(1) from t_dypay_operators_detail a left join t_dypay_operators_receive b on a.id = b.operator_auth_id where 1=1 ");
		return sb.toString();
	}

	@Override
	protected String getSearchHQL() {
		StringBuffer sb = new StringBuffer();
		sb.append("select a.account_no,a.name,a.pid,to_char(a.created_at,'YYYY-MM-DD HH24:mi:ss'),to_char(b.create_at,'YYYY-MM-DD HH24:mi:ss'),");
		sb.append("case when a.status = '0' then '' when a.status='3' then '' else to_char(a.updated_at, 'YYYY-MM-DD HH24:mi:ss') end,");
		sb.append("case when a.status = '3' then b.op_accountno else a.updated_by end oprNo,");
		sb.append("case when a.status = '0' then '未领取' when a.status = '1' then '审核通过' when a.status = '2' then '驳回' ");
		sb.append("when a.status = '3' then '待审核' when a.status = '4' then '限制' else '其他' end status,a.id detailId,b.id receiveId,a.ext5 ");
		sb.append(" from t_dypay_operators_detail a left join t_dypay_operators_receive b on a.id = b.operator_auth_id where 1=1 ");
		return sb.toString();
	}

	@Override
	protected String getOrderPartOfHQL() {
		return " order by a.created_at desc ";
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getMerName() {
		return merName;
	}

	public void setMerName(String merName) {
		this.merName = merName;
	}

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public String getOprNo() {
		return oprNo;
	}

	public void setOprNo(String oprNo) {
		this.oprNo = oprNo;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getMinDate() {
		return minDate;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public String getMaxDate() {
		return maxDate;
	}

	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}

	public String getIdCardStatus() {
		return idCardStatus;
	}

	public void setIdCardStatus(String idCardStatus) {
		this.idCardStatus = idCardStatus;
	}
	
	

}
